<?php

namespace App\Admin\Extensions;

use Encore\Admin\Form\Field;
use Encore\Admin\Admin;

class Button extends Field
{
    public function render()
    {
        Admin::script(
       <<<EOT
$('.btn-check').unbind('click').click(function() {

    var pid = $('#pid').val();
    console.log(pid);
    if(pid == ''){
        alert('书籍ID不能为空！');
    }
    $.ajax({
            method: 'get',
            url: '/product/detail/' + pid,
            
            success: function (data) {
                

                if (typeof data === 'object') {
                    if (data.data != '') {
                        
                        $('#name').val(data.data.name);
                    } else {
                        alert('查询结果为空！');
                    }
                }
            }
        });
});
EOT
);
        
        return <<<EOT
        
<div class="form-group  ">
    <label for="url" class="col-sm-2 control-label">查询</label>
    <div class="col-sm-8">
        <div class="input-group">
            <button type="button" class="btn btn-sm btn-default btn-check">点击查询</button>
        </div>
        <span class="help-block">
    		<i class="fa fa-info-circle"></i> 点击查询输入的书籍的信息
		</span>
    </div>
</div>

EOT;

    }
}